package com.bjsxt.userscenter.back.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bjsxt.userscenter.users.pojo.AAdmins;

/**
 * 管理员登陆的拦截器
 * 
 * @author wangshSxt
 *
 */
@Component("authInterceptor")
public class AuthInterceptor extends HandlerInterceptorAdapter
{
	/**
	 * 验证session中是否有管理员对象
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		String info = "" ; 
		HttpSession session = request.getSession() ;
		AAdmins admins = (AAdmins) session.getAttribute("admins");
		if(admins != null)
		{
			return true ; 
		}
		
		info = "非法访问,请先登陆" ;
		session.setAttribute("info", info);
		
		/* 客户端跳转 */
		response.sendRedirect(request.getContextPath() + "/login.htm");
		return false;
	}

}
